/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.plugins.impl;

import org.grayrabbit.cms.dao.plugins.SurveyRecordDao;
import org.grayrabbit.cms.entity.SurveyRecord;
import org.grayrabbit.cms.service.plugins.SurveyRecordService;
import org.grayrabbit.cms.vo.plugins.SurveyRecordBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：





 * @version 1.0,创建时间: 2011-05-16 16:08:56  
 */
@Service
@Transactional
public class SurveyRecordServiceImpl extends GenericServiceImpl implements SurveyRecordService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("surveyRecordDaoImpl")
	private SurveyRecordDao surveyRecordDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see SurveyRecordService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public SurveyRecord getSurveyRecord(final String recordId){
		SurveyRecord surveyRecord = surveyRecordDao.findById(recordId);
		surveyRecordDao.initialize(surveyRecord);
		return surveyRecord;
	}
	
	/**
	 * @see SurveyRecordService#delete(String)
	 */
	@Transactional
	public void delete(final SurveyRecord surveyRecord) {
		surveyRecordDao.makeTransient(surveyRecord);
	}
	
	/**
	 * @see SurveyRecordService#save(OperLog)
	 */
	@Transactional
	public void save(final SurveyRecord surveyRecord) {
		surveyRecordDao.makePersistent(surveyRecord);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see SurveyRecordService#getPage(SurveyRecordBean)
	 */
	@Transactional(readOnly=true)
	public Page<SurveyRecord> getPage(final SurveyRecordBean surveyRecordBean){
		Page<SurveyRecord> page =  new Page<SurveyRecord>();
		page.setTotal(surveyRecordDao.count(surveyRecordBean));
		page.setResult(surveyRecordDao.findByQc(surveyRecordDao.assembly(surveyRecordBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see SurveyRecordService#list(Page, SurveyRecordBean)
	 */
	public void list(Page<SurveyRecord> page, SurveyRecordBean surveyRecordBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(surveyRecordDao.count(surveyRecordBean));
		}
		page.setResult(surveyRecordDao.findByPage(page,surveyRecordBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see SurveyRecordService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			surveyRecordDao.makeTransient(surveyRecordDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				surveyRecordDao.clear();
		}
		
	}
 
}